<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        组件外的数据{{msg}}
        <parent></parent>
    </div>
    <template id="temp">
        <div>
            <h1>这是父组件</h1>
            <p>接收子组件传来的数据为:{{msg}}</p>
            <hr>
            <child @cevent="recvmsg"></child>
        </div>
    </template>

    <template id="child">
        <div>
                <h1>这是子组件</h1>
                <button @click='sendmsg'>传递给父组件的数据</button>
        </div>
    </template>
    <script type="text/javaScript" charset="UTF-8" src="/JS文件/vue.js"></script>
    <script>
        Vue.component("parent",{
            template:"#temp",
            data(){
                return {
                    msg:""
                }
            },
            methods:{
                recvmsg(childmsg){
                    this.msg=childmsg
                }
            }
        })
        Vue.component("child",{
            template:"#child",
            data(){
                return {
                    age:10
                }
            },
            methods:{
                sendmsg(){
                    this.age+=30
                    this.$emit('cevent','Vue.js很棒！年龄'+this.age)
                }
            }
        })
        var vm = new Vue({
            el:"#app",
            data:{
                msg:"hello world"
            }
        })
    </script>
</body>
</html>